package com.infodms.dms.actions.sales.ordermanage.orderaudit;

import java.sql.ResultSet;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.bean.AclUserBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.ErrorCodeConstant;
import com.infodms.dms.common.getCompanyId.GetOemcompanyId;
import com.infodms.dms.common.materialManager.MaterialGroupManagerDao;
import com.infodms.dms.dao.common.BaseDao;
import com.infodms.dms.dao.sales.ordermanage.orderreport.OrderReportDao;
import com.infodms.dms.dao.sales.ordermanage.resourceQuery.ResourceQueryDAO;
import com.infodms.dms.exception.BizException;
import com.infodms.dms.po.TmDateSetPO;
import com.infodms.dms.util.CommonUtils;
import com.infoservice.mvc.context.ActionContext;
import com.infoservice.mvc.context.RequestWrapper;
import com.infoservice.po3.bean.PO;
import com.infoservice.po3.bean.PageResult;

public class ResourceQuery extends BaseDao<PO>{
	public Logger logger = Logger.getLogger(ResourceQuery.class);
	private ActionContext act = ActionContext.getContext();
	private static final ResourceQueryDAO dao = new ResourceQueryDAO ();
	public static final ResourceQueryDAO getInstance() {
		return dao;
	}
	private final String  resourceQueryInitUrl = "/jsp/sales/ordermanage/orderaudit/resourceQueryInit.jsp";
	//private final String  VehicleDetailUrl = "/jsp/sales/storageManage/vehicleDetail.jsp";
	
	/**
	 * FUNCTION		:	可利用资源查询面初始化
	 * @param 		:	
	 * @return		:
	 * @throws		:	
	 * LastUpdate	:	2010-8-30
	 */
	public void resourceQueryInit(){
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
			Long poseId = logonUser.getPoseId();
			List<Map<String, Object>> areaList = MaterialGroupManagerDao
					.getPoseIdBusiness(poseId.toString());
			act.setOutData("areaList", areaList);
			act.setForword(resourceQueryInitUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "车辆验收");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	} 
	/**
	 * FUNCTION		:	可利用资源查询:结果展示
	 * @param 		:	
	 * @return		:
	 * @throws		:	
	 * LastUpdate	:	2010-8-30
	 */
	public void resourceQueryList(){
		AclUserBean logonUser = null;
		try {
			RequestWrapper request = act.getRequest();
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);	
			String groupCode = CommonUtils.checkNull(request.getParamValue("materialCode"));		//物料组
			String areaId = CommonUtils.checkNull(request.getParamValue("areaId"));					//业务范围
			String resStatus = CommonUtils.checkNull(request.getParamValue("resStatus"));			//资源状态
			
			if("".equals(areaId)) {
				Long poseId = logonUser.getPoseId();
				List<Map<String, Object>> areaList = MaterialGroupManagerDao
						.getPoseIdBusiness(poseId.toString());
				for (int i=0; i< areaList.size();i++) {
					areaId += areaList.get(i).get("AREA_ID").toString()+",";
				}
				if (!"".equals(areaId)) {
					areaId = areaId.substring(0, areaId.length()-1);
				}
			}
			
			Long oemCompanyId = GetOemcompanyId.getOemCompanyId(logonUser);
			
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage")) 
					: 1; // 处理当前页
			PageResult<Map<String, Object>> ps = ResourceQueryDAO.getResourceQueryList(resStatus , areaId , groupCode , oemCompanyId , Constant.PAGE_SIZE, curPage);
			act.setOutData("ps", ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "车辆验收");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	} 
	
	
	@Override
	protected PO wrapperPO(ResultSet rs, int idx) {
		// TODO Auto-generated method stub
		return null;
	}
}
